#coding:utf-8
__author__ = 'Administrator'
import sys
import urllib2
import urllib
import cookielib
import socket

#####################################################
#登录手机人人

class UserRR(object):

    def __init__(self,name,pwd):
        self.name = name
        self.pwd = pwd

        self.cj = cookielib.LWPCookieJar()
        self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
        urllib2.install_opener(self.opener)

    def setLoginInfo(self,username,password):
        '''设置用户登录信息'''
        self.name = username
        self.pwd = password

    def login(self):
        '''登录网站'''
        login_url = 'http://3g.renren.com/login.do?'
        login_params = {'email':self.name, 'password':self.pwd}
        headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36'}
        req = urllib2.Request(login_url, urllib.urlencode(login_params),headers=headers)
        try:
            response = urllib2.urlopen(req,timeout=3)
            page = response.read()
            str_page = str(page)
            #print(str_page)

            if '验证码' in str_page:
                return 2
            elif '密码(区分大小写)' in str_page:
                return 0
            else:
                return 1
        except urllib2.URLError,e:
            return 3




#使用测试
if __name__ == '__main__':
  user = UserRR('545127804@qq.com','8382117')
  user.login()
  user1 = UserRR('545127804@qq.com','88544646')
  user1.login()